import time

import pyautogui as pg
import pyperclip as pp

from sam.util.fileUtil2 import read_file_quick, write_file_quick


class SmallProgramSearch(object):
    def __init__(self):
        super().__init__()

    def search_one(self, keyword: str):
        pp.copy(keyword)
        pg.moveTo(860, 150)
        pg.click()
        pg.press(keys="backspace", presses=20, interval=0.1)
        pg.moveTo(460, 150)
        pg.click()
        pg.hotkey('ctrlleft', 'v')
        time.sleep(1)
        pg.press(keys="enter")
        pg.press(keys="enter")
        time.sleep(3)
        confirm = pg.confirm('这个消息弹窗是文字+OK+Cancel按钮')
        print(f"关键词: {keyword} , 结果是 {confirm}")
        return confirm

    def main(self):
        keyword_list = read_file_quick(file_type="csv")
        for keyword in keyword_list:
            one = self.search_one(keyword)
            write_file_quick([keyword, one], export_file_name="博物馆", optional="append")


def main():
    pg.moveTo(460, 150)
    pg.click()
    SmallProgramSearch().main()


if __name__ == "__main__":
    main()
